source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-337.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.156.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
3962 3789 5482 5689 1955 3188 3654 4025 3636 4547 4866 3832 3739 5121 4197 3131
17 18 19 20 21 22 23 24 25
4437 4117 3892 3256 1899 3633 3785 4283 766
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin
[1,] -0.1042546 -0.8954702 -0.8972276
[2,] -0.8533906 -0.1765840 -0.2110912
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
fecha_cnt tmin tmax
0.9766933 0.9750699 0.9735719
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 3.000 Min. :172.0 Min. : 26.0 Min. : 0.0 Min. :0
1st Qu.: 6.000 1st Qu.:233.0 1st Qu.:126.0 1st Qu.: 1.0 1st Qu.:0
Median : 8.000 Median :262.0 Median :151.0 Median : 6.0 Median :0
Mean : 7.587 Mean :264.8 Mean :152.3 Mean : 10.9 Mean :0
3rd Qu.: 9.000 3rd Qu.:293.0 3rd Qu.:179.0 3rd Qu.: 15.0 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.: -5.6983 1st Qu.: 33.0
Median : 0.00000 Median :40.41 Median : -3.4503 Median : 98.0
Mean : 0.00355 Mean :39.13 Mean : -3.6413 Mean : 315.7
3rd Qu.: 0.00000 3rd Qu.:41.70 3rd Qu.: 0.4731 3rd Qu.: 582.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 8.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.:115.0 1st Qu.: 28.00 1st Qu.: 6.00
Median :11.00 Median :147.0 Median : 58.00 Median : 16.00
Mean :11.21 Mean :141.7 Mean : 54.87 Mean : 23.75
3rd Qu.:12.00 3rd Qu.:174.0 3rd Qu.: 84.00 3rd Qu.: 33.00
Max. :12.00 Max. :223.0 Max. : 143.00 Max. :299.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -5.4981
Median :0.0000000 Median : 0.0000 Median :41.15 Median : -2.9056
Mean :0.0005093 Mean : 0.3386 Mean :40.53 Mean : -2.8760
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.36 3rd Qu.: 0.4914
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 69.0
Median : 442.0
Mean : 551.5
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:125.0 1st Qu.: 27.00 1st Qu.: 5.00
Median :3.000 Median :157.0 Median : 58.00 Median : 13.00
Mean :2.798 Mean :151.7 Mean : 56.43 Mean : 18.92
3rd Qu.:4.000 3rd Qu.:184.0 3rd Qu.: 84.00 3rd Qu.: 26.00
Max. :7.000 Max. :258.0 Max. : 185.00 Max. :371.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:38.88 1st Qu.: -5.6417
Median :0.000000 Median : 0.000 Median :40.96 Median : -3.4503
Mean :0.000544 Mean : 1.092 Mean :39.87 Mean : -3.4682
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.33 3rd Qu.: 0.4914
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 316.0
Mean : 475.6
3rd Qu.: 690.0
Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 3.000 Min. :172.0 Min. : 26.0 Min. : 0.0 Min. :0
1st Qu.: 6.000 1st Qu.:233.0 1st Qu.:126.0 1st Qu.: 1.0 1st Qu.:0
Median : 8.000 Median :262.0 Median :151.0 Median : 6.0 Median :0
Mean : 7.587 Mean :264.8 Mean :152.3 Mean : 10.9 Mean :0
3rd Qu.: 9.000 3rd Qu.:293.0 3rd Qu.:179.0 3rd Qu.: 15.0 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.: -5.6983 1st Qu.: 33.0
Median : 0.00000 Median :40.41 Median : -3.4503 Median : 98.0
Mean : 0.00355 Mean :39.13 Mean : -3.6413 Mean : 315.7
3rd Qu.: 0.00000 3rd Qu.:41.70 3rd Qu.: 0.4731 3rd Qu.: 582.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 8.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.:115.0 1st Qu.: 28.00 1st Qu.: 6.00
Median :11.00 Median :147.0 Median : 58.00 Median : 16.00
Mean :11.21 Mean :141.7 Mean : 54.87 Mean : 23.75
3rd Qu.:12.00 3rd Qu.:174.0 3rd Qu.: 84.00 3rd Qu.: 33.00
Max. :12.00 Max. :223.0 Max. : 143.00 Max. :299.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -5.4981
Median :0.0000000 Median : 0.0000 Median :41.15 Median : -2.9056
Mean :0.0005093 Mean : 0.3386 Mean :40.53 Mean : -2.8760
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.36 3rd Qu.: 0.4914
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 69.0
Median : 442.0
Mean : 551.5
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 14.00 Min. : 0.00 Min. :0
1st Qu.:2.000 1st Qu.:155.0 1st Qu.: 59.00 1st Qu.: 5.00 1st Qu.:0
Median :3.000 Median :175.0 Median : 76.00 Median : 14.00 Median :0
Mean :3.155 Mean :175.1 Mean : 81.08 Mean : 19.18 Mean :0
3rd Qu.:4.000 3rd Qu.:195.0 3rd Qu.: 96.00 3rd Qu.: 27.00 3rd Qu.:0
Max. :7.000 Max. :258.0 Max. :185.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.: -6.0442 1st Qu.: 27.0
Median : 0.00000 Median :40.66 Median : -3.6781 Median : 85.0
Mean : 0.04773 Mean :39.28 Mean : -3.8560 Mean : 289.2
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.4914 3rd Qu.: 445.0
Max. :41.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.000 Min. : 0.00
1st Qu.:1.000 1st Qu.: 88.0 1st Qu.: -4.000 1st Qu.: 5.00
Median :2.000 Median :111.0 Median : 15.000 Median : 13.00
Mean :2.124 Mean :107.5 Mean : 9.945 Mean : 18.42
3rd Qu.:3.000 3rd Qu.:132.0 3rd Qu.: 29.000 3rd Qu.: 24.00
Max. :7.000 Max. :250.0 Max. : 61.000 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -4.5353
Median :0.000000 Median : 0.000 Median :41.60 Median : -2.7331
Mean :0.001569 Mean : 3.062 Mean :40.99 Mean : -2.7370
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4483
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 459.0
Median : 691.0
Mean : 827.1
3rd Qu.: 990.0
Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 5.000 Min. :217 Min. :111.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:281 1st Qu.:167.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :301 Median :184.0 Median : 2.000 Median :0
Mean : 7.866 Mean :301 Mean :184.8 Mean : 6.275 Mean :0
3rd Qu.: 9.000 3rd Qu.:321 3rd Qu.:203.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:37.19 1st Qu.: -5.6156 1st Qu.: 27.0
Median :0.0000000 Median :39.01 Median : -2.9056 Median : 81.0
Mean :0.0001276 Mean :38.28 Mean : -3.4573 Mean : 231.1
3rd Qu.:0.0000000 3rd Qu.:41.11 3rd Qu.: 0.4942 3rd Qu.: 459.0
Max. :2.0000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 3.000 Min. :172.0 Min. : 26.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:223.0 1st Qu.:114.0 1st Qu.: 3.00 1st Qu.:0
Median : 7.000 Median :241.0 Median :133.0 Median : 9.00 Median :0
Mean : 7.422 Mean :243.5 Mean :133.2 Mean : 13.63 Mean :0
3rd Qu.: 9.000 3rd Qu.:264.0 3rd Qu.:151.0 3rd Qu.: 19.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :215.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.: -5.7333 1st Qu.: 35.0
Median : 0.00000 Median :40.95 Median : -3.6325 Median : 185.0
Mean : 0.00557 Mean :39.63 Mean : -3.7498 Mean : 365.6
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.3264 3rd Qu.: 632.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 8.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.:115.0 1st Qu.: 28.00 1st Qu.: 6.00
Median :11.00 Median :147.0 Median : 58.00 Median : 16.00
Mean :11.21 Mean :141.7 Mean : 54.87 Mean : 23.75
3rd Qu.:12.00 3rd Qu.:174.0 3rd Qu.: 84.00 3rd Qu.: 33.00
Max. :12.00 Max. :223.0 Max. : 143.00 Max. :299.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -5.4981
Median :0.0000000 Median : 0.0000 Median :41.15 Median : -2.9056
Mean :0.0005093 Mean : 0.3386 Mean :40.53 Mean : -2.8760
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.36 3rd Qu.: 0.4914
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 69.0
Median : 442.0
Mean : 551.5
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 14.00 Min. : 0.00 Min. :0
1st Qu.:2.000 1st Qu.:155.0 1st Qu.: 59.00 1st Qu.: 5.00 1st Qu.:0
Median :3.000 Median :175.0 Median : 76.00 Median : 14.00 Median :0
Mean :3.155 Mean :175.1 Mean : 81.08 Mean : 19.18 Mean :0
3rd Qu.:4.000 3rd Qu.:195.0 3rd Qu.: 96.00 3rd Qu.: 27.00 3rd Qu.:0
Max. :7.000 Max. :258.0 Max. :185.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.: -6.0442 1st Qu.: 27.0
Median : 0.00000 Median :40.66 Median : -3.6781 Median : 85.0
Mean : 0.04773 Mean :39.28 Mean : -3.8560 Mean : 289.2
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.4914 3rd Qu.: 445.0
Max. :41.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.000 Min. : 0.00
1st Qu.:1.000 1st Qu.: 88.0 1st Qu.: -4.000 1st Qu.: 5.00
Median :2.000 Median :111.0 Median : 15.000 Median : 13.00
Mean :2.124 Mean :107.5 Mean : 9.945 Mean : 18.42
3rd Qu.:3.000 3rd Qu.:132.0 3rd Qu.: 29.000 3rd Qu.: 24.00
Max. :7.000 Max. :250.0 Max. : 61.000 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -4.5353
Median :0.000000 Median : 0.000 Median :41.60 Median : -2.7331
Mean :0.001569 Mean : 3.062 Mean :40.99 Mean : -2.7370
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4483
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 459.0
Median : 691.0
Mean : 827.1
3rd Qu.: 990.0
Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 5.000 Min. :217 Min. :111.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:281 1st Qu.:167.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :301 Median :184.0 Median : 2.000 Median :0
Mean : 7.866 Mean :301 Mean :184.8 Mean : 6.275 Mean :0
3rd Qu.: 9.000 3rd Qu.:321 3rd Qu.:203.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:37.19 1st Qu.: -5.6156 1st Qu.: 27.0
Median :0.0000000 Median :39.01 Median : -2.9056 Median : 81.0
Mean :0.0001276 Mean :38.28 Mean : -3.4573 Mean : 231.1
3rd Qu.:0.0000000 3rd Qu.:41.11 3rd Qu.: 0.4942 3rd Qu.: 459.0
Max. :2.0000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 3.000 Min. :172.0 Min. : 26.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:223.0 1st Qu.:114.0 1st Qu.: 3.00 1st Qu.:0
Median : 7.000 Median :241.0 Median :133.0 Median : 9.00 Median :0
Mean : 7.422 Mean :243.5 Mean :133.2 Mean : 13.63 Mean :0
3rd Qu.: 9.000 3rd Qu.:264.0 3rd Qu.:151.0 3rd Qu.: 19.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :215.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.: -5.7333 1st Qu.: 35.0
Median : 0.00000 Median :40.95 Median : -3.6325 Median : 185.0
Mean : 0.00557 Mean :39.63 Mean : -3.7498 Mean : 365.6
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.3264 3rd Qu.: 632.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 8 Min. : 95.0 Min. : 2.00 Min. : 0.00 Min. :0
1st Qu.:10 1st Qu.:149.0 1st Qu.: 61.00 1st Qu.: 7.00 1st Qu.:0
Median :11 Median :167.0 Median : 77.00 Median : 19.00 Median :0
Mean :11 Mean :165.9 Mean : 77.76 Mean : 26.04 Mean :0
3rd Qu.:12 3rd Qu.:183.0 3rd Qu.: 95.00 3rd Qu.: 36.00 3rd Qu.:0
Max. :12 Max. :223.0 Max. :143.00 Max. :299.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.92 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.37 1st Qu.: -5.6417 1st Qu.: 35.0
Median : 0.00000 Median :40.96 Median : -2.9553 Median : 127.0
Mean : 0.04368 Mean :40.26 Mean : -2.9701 Mean : 363.4
3rd Qu.: 0.00000 3rd Qu.:42.38 3rd Qu.: 0.4914 3rd Qu.: 567.0
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 8.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.: 86.0 1st Qu.: 1.00 1st Qu.: 5.00
Median :12.00 Median :105.0 Median : 19.00 Median : 13.00
Mean :11.57 Mean :100.2 Mean : 15.56 Mean : 19.82
3rd Qu.:12.00 3rd Qu.:119.0 3rd Qu.: 34.00 3rd Qu.: 27.00
Max. :12.00 Max. :176.0 Max. : 68.00 Max. :252.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.66 1st Qu.: -4.1269
Median :0.000000 Median : 0.0000 Median :41.60 Median : -2.6544
Mean :0.001384 Mean : 0.8453 Mean :40.99 Mean : -2.7142
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.36 3rd Qu.: 0.4914
Max. :3.000000 Max. :382.0000 Max. :43.57 Max. : 3.1817
altitud
Min. : 2.0
1st Qu.: 513.0
Median : 704.0
Mean : 874.7
3rd Qu.:1004.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 14.00 Min. : 0.00 Min. :0
1st Qu.:2.000 1st Qu.:155.0 1st Qu.: 59.00 1st Qu.: 5.00 1st Qu.:0
Median :3.000 Median :175.0 Median : 76.00 Median : 14.00 Median :0
Mean :3.155 Mean :175.1 Mean : 81.08 Mean : 19.18 Mean :0
3rd Qu.:4.000 3rd Qu.:195.0 3rd Qu.: 96.00 3rd Qu.: 27.00 3rd Qu.:0
Max. :7.000 Max. :258.0 Max. :185.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.: -6.0442 1st Qu.: 27.0
Median : 0.00000 Median :40.66 Median : -3.6781 Median : 85.0
Mean : 0.04773 Mean :39.28 Mean : -3.8560 Mean : 289.2
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.4914 3rd Qu.: 445.0
Max. :41.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.0 Min. :-121.000 Min. : 0.00
1st Qu.:1.000 1st Qu.: 88.0 1st Qu.: -4.000 1st Qu.: 5.00
Median :2.000 Median :111.0 Median : 15.000 Median : 13.00
Mean :2.124 Mean :107.5 Mean : 9.945 Mean : 18.42
3rd Qu.:3.000 3rd Qu.:132.0 3rd Qu.: 29.000 3rd Qu.: 24.00
Max. :7.000 Max. :250.0 Max. : 61.000 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -4.5353
Median :0.000000 Median : 0.000 Median :41.60 Median : -2.7331
Mean :0.001569 Mean : 3.062 Mean :40.99 Mean : -2.7370
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4483
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 459.0
Median : 691.0
Mean : 827.1
3rd Qu.: 990.0
Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 5.000 Min. :217 Min. :111.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:281 1st Qu.:167.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :301 Median :184.0 Median : 2.000 Median :0
Mean : 7.866 Mean :301 Mean :184.8 Mean : 6.275 Mean :0
3rd Qu.: 9.000 3rd Qu.:321 3rd Qu.:203.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:37.19 1st Qu.: -5.6156 1st Qu.: 27.0
Median :0.0000000 Median :39.01 Median : -2.9056 Median : 81.0
Mean :0.0001276 Mean :38.28 Mean : -3.4573 Mean : 231.1
3rd Qu.:0.0000000 3rd Qu.:41.11 3rd Qu.: 0.4942 3rd Qu.: 459.0
Max. :2.0000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 8.000 Min. :172 Min. : 26.0 Min. : 0.00 Min. :0
1st Qu.: 9.000 1st Qu.:218 1st Qu.:111.0 1st Qu.: 4.00 1st Qu.:0
Median : 9.000 Median :236 Median :129.0 Median : 11.00 Median :0
Mean : 9.486 Mean :239 Mean :127.2 Mean : 16.78 Mean :0
3rd Qu.:10.000 3rd Qu.:259 3rd Qu.:145.0 3rd Qu.: 23.00 3rd Qu.:0
Max. :12.000 Max. :321 Max. :192.0 Max. :206.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.: -5.6492 1st Qu.: 44.0
Median : 0.00000 Median :40.96 Median : -3.6325 Median : 263.0
Mean : 0.01153 Mean :39.86 Mean : -3.6453 Mean : 402.2
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.3181 3rd Qu.: 667.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 8 Min. : 95.0 Min. : 2.00 Min. : 0.00 Min. :0
1st Qu.:10 1st Qu.:149.0 1st Qu.: 61.00 1st Qu.: 7.00 1st Qu.:0
Median :11 Median :167.0 Median : 77.00 Median : 19.00 Median :0
Mean :11 Mean :165.9 Mean : 77.76 Mean : 26.04 Mean :0
3rd Qu.:12 3rd Qu.:183.0 3rd Qu.: 95.00 3rd Qu.: 36.00 3rd Qu.:0
Max. :12 Max. :223.0 Max. :143.00 Max. :299.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.92 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.37 1st Qu.: -5.6417 1st Qu.: 35.0
Median : 0.00000 Median :40.96 Median : -2.9553 Median : 127.0
Mean : 0.04368 Mean :40.26 Mean : -2.9701 Mean : 363.4
3rd Qu.: 0.00000 3rd Qu.:42.38 3rd Qu.: 0.4914 3rd Qu.: 567.0
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 8.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.: 86.0 1st Qu.: 1.00 1st Qu.: 5.00
Median :12.00 Median :105.0 Median : 19.00 Median : 13.00
Mean :11.57 Mean :100.2 Mean : 15.56 Mean : 19.82
3rd Qu.:12.00 3rd Qu.:119.0 3rd Qu.: 34.00 3rd Qu.: 27.00
Max. :12.00 Max. :176.0 Max. : 68.00 Max. :252.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.66 1st Qu.: -4.1269
Median :0.000000 Median : 0.0000 Median :41.60 Median : -2.6544
Mean :0.001384 Mean : 0.8453 Mean :40.99 Mean : -2.7142
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.36 3rd Qu.: 0.4914
Max. :3.000000 Max. :382.0000 Max. :43.57 Max. : 3.1817
altitud
Min. : 2.0
1st Qu.: 513.0
Median : 704.0
Mean : 874.7
3rd Qu.:1004.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :3.000 Min. :178.0 Min. : 57.0 Min. : 0.00 Min. :0
1st Qu.:5.000 1st Qu.:227.0 1st Qu.:116.0 1st Qu.: 2.00 1st Qu.:0
Median :6.000 Median :245.0 Median :136.0 Median : 8.00 Median :0
Mean :5.861 Mean :246.8 Mean :137.7 Mean : 11.25 Mean :0
3rd Qu.:6.000 3rd Qu.:266.0 3rd Qu.:158.0 3rd Qu.: 16.00 3rd Qu.:0
Max. :8.000 Max. :336.0 Max. :215.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.000000 1st Qu.:37.84 1st Qu.: -5.8728 1st Qu.: 33
Median : 0.000000 Median :40.82 Median : -3.6325 Median : 108
Mean : 0.001057 Mean :39.45 Mean : -3.8289 Mean : 338
3rd Qu.: 0.000000 3rd Qu.:42.23 3rd Qu.: 0.3664 3rd Qu.: 609
Max. :11.000000 Max. :43.57 Max. : 4.2156 Max. :2371
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 14.00 Min. : 0.00 Min. :0
1st Qu.:2.000 1st Qu.:155.0 1st Qu.: 59.00 1st Qu.: 5.00 1st Qu.:0
Median :3.000 Median :175.0 Median : 76.00 Median : 14.00 Median :0
Mean :3.155 Mean :175.1 Mean : 81.08 Mean : 19.18 Mean :0
3rd Qu.:4.000 3rd Qu.:195.0 3rd Qu.: 96.00 3rd Qu.: 27.00 3rd Qu.:0
Max. :7.000 Max. :258.0 Max. :185.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.: -6.0442 1st Qu.: 27.0
Median : 0.00000 Median :40.66 Median : -3.6781 Median : 85.0
Mean : 0.04773 Mean :39.28 Mean : -3.8560 Mean : 289.2
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.4914 3rd Qu.: 445.0
Max. :41.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : 36.0 Min. :-80.0 Min. : 0.00
1st Qu.:1.000 1st Qu.: 93.0 1st Qu.: 0.0 1st Qu.: 5.00
Median :2.000 Median :113.0 Median : 17.0 Median : 12.00
Mean :2.112 Mean :113.6 Mean : 13.9 Mean : 17.21
3rd Qu.:3.000 3rd Qu.:133.0 3rd Qu.: 30.0 3rd Qu.: 23.00
Max. :7.000 Max. :250.0 Max. : 61.0 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.63 1st Qu.: -4.680
Median :0.000000 Median : 0.000 Median :41.52 Median : -2.906
Mean :0.001675 Mean : 0.966 Mean :40.92 Mean : -2.894
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: -1.008
Max. :6.000000 Max. :666.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 445.0
Median : 674.0
Mean : 743.9
3rd Qu.: 916.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.:1.000 1st Qu.: 3.00 1st Qu.: -61.75 1st Qu.: 16.25
Median :2.000 Median : 21.00 Median : -45.00 Median : 31.50
Mean :2.305 Mean : 18.14 Mean : -48.66 Mean : 36.34
3rd Qu.:3.000 3rd Qu.: 36.00 3rd Qu.: -33.00 3rd Qu.: 51.00
Max. :6.000 Max. : 84.00 Max. : -4.00 Max. :180.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.0 Min. :28.31 Min. :-16.4992 Min. : 4
1st Qu.:0 1st Qu.: 0.0 1st Qu.:41.00 1st Qu.: -3.6325 1st Qu.:1894
Median :0 Median : 0.0 Median :42.47 Median : 0.8842 Median :2230
Mean :0 Mean : 34.1 Mean :41.93 Mean : -0.4168 Mean :2059
3rd Qu.:0 3rd Qu.: 0.0 3rd Qu.:42.64 3rd Qu.: 1.3656 3rd Qu.:2400
Max. :0 Max. :1834.0 Max. :43.36 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 5.000 Min. :217 Min. :111.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:281 1st Qu.:167.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :301 Median :184.0 Median : 2.000 Median :0
Mean : 7.866 Mean :301 Mean :184.8 Mean : 6.275 Mean :0
3rd Qu.: 9.000 3rd Qu.:321 3rd Qu.:203.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254.0 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:37.19 1st Qu.: -5.6156 1st Qu.: 27.0
Median :0.0000000 Median :39.01 Median : -2.9056 Median : 81.0
Mean :0.0001276 Mean :38.28 Mean : -3.4573 Mean : 231.1
3rd Qu.:0.0000000 3rd Qu.:41.11 3rd Qu.: 0.4942 3rd Qu.: 459.0
Max. :2.0000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 8.000 Min. :172 Min. : 26.0 Min. : 0.00 Min. :0
1st Qu.: 9.000 1st Qu.:218 1st Qu.:111.0 1st Qu.: 4.00 1st Qu.:0
Median : 9.000 Median :236 Median :129.0 Median : 11.00 Median :0
Mean : 9.486 Mean :239 Mean :127.2 Mean : 16.78 Mean :0
3rd Qu.:10.000 3rd Qu.:259 3rd Qu.:145.0 3rd Qu.: 23.00 3rd Qu.:0
Max. :12.000 Max. :321 Max. :192.0 Max. :206.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.: -5.6492 1st Qu.: 44.0
Median : 0.00000 Median :40.96 Median : -3.6325 Median : 263.0
Mean : 0.01153 Mean :39.86 Mean : -3.6453 Mean : 402.2
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.3181 3rd Qu.: 667.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 8 Min. : 95.0 Min. : 2.00 Min. : 0.00 Min. :0
1st Qu.:10 1st Qu.:149.0 1st Qu.: 61.00 1st Qu.: 7.00 1st Qu.:0
Median :11 Median :167.0 Median : 77.00 Median : 19.00 Median :0
Mean :11 Mean :165.9 Mean : 77.76 Mean : 26.04 Mean :0
3rd Qu.:12 3rd Qu.:183.0 3rd Qu.: 95.00 3rd Qu.: 36.00 3rd Qu.:0
Max. :12 Max. :223.0 Max. :143.00 Max. :299.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.92 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.37 1st Qu.: -5.6417 1st Qu.: 35.0
Median : 0.00000 Median :40.96 Median : -2.9553 Median : 127.0
Mean : 0.04368 Mean :40.26 Mean : -2.9701 Mean : 363.4
3rd Qu.: 0.00000 3rd Qu.:42.38 3rd Qu.: 0.4914 3rd Qu.: 567.0
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 8.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.: 86.0 1st Qu.: 1.00 1st Qu.: 5.00
Median :12.00 Median :105.0 Median : 19.00 Median : 13.00
Mean :11.57 Mean :100.2 Mean : 15.56 Mean : 19.82
3rd Qu.:12.00 3rd Qu.:119.0 3rd Qu.: 34.00 3rd Qu.: 27.00
Max. :12.00 Max. :176.0 Max. : 68.00 Max. :252.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.66 1st Qu.: -4.1269
Median :0.000000 Median : 0.0000 Median :41.60 Median : -2.6544
Mean :0.001384 Mean : 0.8453 Mean :40.99 Mean : -2.7142
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.36 3rd Qu.: 0.4914
Max. :3.000000 Max. :382.0000 Max. :43.57 Max. : 3.1817
altitud
Min. : 2.0
1st Qu.: 513.0
Median : 704.0
Mean : 874.7
3rd Qu.:1004.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :3.000 Min. :178.0 Min. : 57.0 Min. : 0.00 Min. :0
1st Qu.:5.000 1st Qu.:227.0 1st Qu.:116.0 1st Qu.: 2.00 1st Qu.:0
Median :6.000 Median :245.0 Median :136.0 Median : 8.00 Median :0
Mean :5.861 Mean :246.8 Mean :137.7 Mean : 11.25 Mean :0
3rd Qu.:6.000 3rd Qu.:266.0 3rd Qu.:158.0 3rd Qu.: 16.00 3rd Qu.:0
Max. :8.000 Max. :336.0 Max. :215.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.000000 1st Qu.:37.84 1st Qu.: -5.8728 1st Qu.: 33
Median : 0.000000 Median :40.82 Median : -3.6325 Median : 108
Mean : 0.001057 Mean :39.45 Mean : -3.8289 Mean : 338
3rd Qu.: 0.000000 3rd Qu.:42.23 3rd Qu.: 0.3664 3rd Qu.: 609
Max. :11.000000 Max. :43.57 Max. : 4.2156 Max. :2371
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 99.0 Min. : 14 Min. : 0.00 Min. :0
1st Qu.:2.000 1st Qu.:145.0 1st Qu.: 52 1st Qu.: 6.00 1st Qu.:0
Median :2.000 Median :159.0 Median : 65 Median : 16.00 Median :0
Mean :2.546 Mean :158.2 Mean : 67 Mean : 21.73 Mean :0
3rd Qu.:3.000 3rd Qu.:172.0 3rd Qu.: 80 3rd Qu.: 30.00 3rd Qu.:0
Max. :7.000 Max. :219.0 Max. :137 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.31 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.: -5.6492 1st Qu.: 27.0
Median : 0.00000 Median :40.82 Median : -2.9553 Median : 87.0
Mean : 0.05262 Mean :40.11 Mean : -2.9391 Mean : 281.6
3rd Qu.: 0.00000 3rd Qu.:42.43 3rd Qu.: 0.4942 3rd Qu.: 415.0
Max. :41.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : 36.0 Min. :-80.0 Min. : 0.00
1st Qu.:1.000 1st Qu.: 93.0 1st Qu.: 0.0 1st Qu.: 5.00
Median :2.000 Median :113.0 Median : 17.0 Median : 12.00
Mean :2.112 Mean :113.6 Mean : 13.9 Mean : 17.21
3rd Qu.:3.000 3rd Qu.:133.0 3rd Qu.: 30.0 3rd Qu.: 23.00
Max. :7.000 Max. :250.0 Max. : 61.0 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.63 1st Qu.: -4.680
Median :0.000000 Median : 0.000 Median :41.52 Median : -2.906
Mean :0.001675 Mean : 0.966 Mean :40.92 Mean : -2.894
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: -1.008
Max. :6.000000 Max. :666.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 445.0
Median : 674.0
Mean : 743.9
3rd Qu.: 916.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 20.00 Min. : 0.00 Min. :0
1st Qu.:4.000 1st Qu.:185.0 1st Qu.: 74.00 1st Qu.: 6.00 1st Qu.:0
Median :4.000 Median :195.0 Median : 87.00 Median : 14.00 Median :0
Mean :4.311 Mean :194.5 Mean : 88.29 Mean : 17.74 Mean :0
3rd Qu.:5.000 3rd Qu.:205.0 3rd Qu.:103.00 3rd Qu.: 25.00 3rd Qu.:0
Max. :7.000 Max. :258.0 Max. :157.00 Max. :279.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:38.37 1st Qu.: -5.6417 1st Qu.: 43.3
Median : 0.0000 Median :40.96 Median : -2.9056 Median : 147.0
Mean : 0.0511 Mean :40.16 Mean : -3.0224 Mean : 364.3
3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4914 3rd Qu.: 609.0
Max. :38.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :158.0 Min. :110.0 Min. : 0.000 Min. :0
1st Qu.:2.000 1st Qu.:203.0 1st Qu.:140.0 1st Qu.: 0.000 1st Qu.:0
Median :3.000 Median :212.0 Median :150.0 Median : 3.000 Median :0
Mean :2.668 Mean :213.1 Mean :149.5 Mean : 7.338 Mean :0
3rd Qu.:4.000 3rd Qu.:222.0 3rd Qu.:159.0 3rd Qu.: 10.000 3rd Qu.:0
Max. :4.000 Max. :256.0 Max. :185.0 Max. :145.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.889 Min. : 1.00
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.561 1st Qu.: 24.00
Median :0 Median :28.46 Median :-15.389 Median : 32.00
Mean :0 Mean :29.90 Mean :-13.626 Mean : 35.96
3rd Qu.:0 3rd Qu.:28.95 3rd Qu.:-13.600 3rd Qu.: 35.00
Max. :0 Max. :41.98 Max. : 2.825 Max. :632.00
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.:1.000 1st Qu.: 3.00 1st Qu.: -61.75 1st Qu.: 16.25
Median :2.000 Median : 21.00 Median : -45.00 Median : 31.50
Mean :2.305 Mean : 18.14 Mean : -48.66 Mean : 36.34
3rd Qu.:3.000 3rd Qu.: 36.00 3rd Qu.: -33.00 3rd Qu.: 51.00
Max. :6.000 Max. : 84.00 Max. : -4.00 Max. :180.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.0 Min. :28.31 Min. :-16.4992 Min. : 4
1st Qu.:0 1st Qu.: 0.0 1st Qu.:41.00 1st Qu.: -3.6325 1st Qu.:1894
Median :0 Median : 0.0 Median :42.47 Median : 0.8842 Median :2230
Mean :0 Mean : 34.1 Mean :41.93 Mean : -0.4168 Mean :2059
3rd Qu.:0 3rd Qu.: 0.0 3rd Qu.:42.64 3rd Qu.: 1.3656 3rd Qu.:2400
Max. :0 Max. :1834.0 Max. :43.36 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)